#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>

#define FOR(i,a,n) for(int i=a,_n(n);i<_n;++i)
#define REP(i,n) FOR(i,0,n)

const int INF = 1<<29;

using namespace std;

class DLX
{
    vector<int> cnt;
    vector<int> ans;
    struct Node
    {
        int ri,ci;
        Node *left,*right,*up,*down;
        void Set(Node* l,Node* r,Node* u,Node* d,int a,int b)
        {
            ri = a, ci = b, left = l, right = r, up = u, down = d;
        }
    };
    vector<Node> node,row,col;
    Node head;
    int np;
public:
    DLX(int n,int m)
    {
        node.reserve(n*m);
        row.resize(n);
        col.resize(m);
        cnt.resize(m+1,0);
        head.Set(&head,&head,&head,&head,n,m);
        REP(i,n)
        {
            row[i].Set(&row[i],&row[i],&head,head.down,i,m);
            row[i].down->up = &row[i];
            head.down = &row[i];
        }
        REP(i,m)
        {
            col[i].Set(&head,head.right,&col[i],&col[i],n,i);
            col[i].right->left = &col[i];
            head.right = &col[i];
        }
        np = 0;
    }
    void SetBit(int r,int c)
    {
        cnt[c]++;
        Node* nt = &node[np++];
        nt->Set(&row[r],row[r].right,&col[c],col[c].down,r,c);
        nt->right->left = nt;
        row[r].right = nt;
        nt->down->up = nt;
        col[c].down = nt;
    }
    void Remove(int c)
    {
        col[c].left->right = col[c].right;
        col[c].right->left = col[c].left;
        for(Node* nr=col[c].down; nr!=&col[c]; nr=nr->down)
        {
            for(Node* nc=nr->right; nc!=nr; nc=nc->right)
            {
                --cnt[nc->ci];
                nc->up->down = nc->down;
                nc->down->up = nc->up;
            }
        }
    }
    void Resume(int c)
    {
        for(Node* nr=col[c].down; nr!=&col[c]; nr=nr->down)
        {
            for(Node* nc=nr->left; nc!=nr; nc=nc->left)
            {
                ++cnt[nc->ci];
                nc->up->down = nc;
                nc->down->up = nc;
            }
        }
        col[c].left->right = &col[c];
        col[c].right->left = &col[c];
    }
    bool Dfs()
    {
        if(head.right==&head) return true;
        int tmin = INF,tc;
        for(Node* nt=head.right; nt!=&head; nt=nt->right) if(cnt[nt->ci]<tmin)
            {
                tmin = cnt[nt->ci];
                tc = nt->ci;
                if(tmin<=1) break;
            }
        Remove(tc);
        for(Node* nr=col[tc].down; nr!=&col[tc]; nr=nr->down)
        {
            for(Node* nc=nr->right; nc!=nr; nc=nc->right)
            {
                if(nc->ci==col.size()) continue;
                Remove(nc->ci);
            }
            if(Dfs())
            {
                ans.push_back(nr->ri);
                return true;
            }
            for(Node* nc=nr->left; nc!=nr; nc=nc->left)
            {
                if(nc->ci==col.size()) continue;
                Resume(nc->ci);
            }
        }
        Resume(tc);
        return false;
    }
    void PrintAns()
    {
        Dfs();
        sort(ans.begin(),ans.end());
        REP(i,81)
        {
            putchar(ans[i]%9+'1');
            if((i+1)%9==0) puts("");
        }
        puts("");
    }
};
char mp[100];
int main()
{
    const int SI = 9;
    while(~scanf("%s",mp))
    {
        if(strcmp(mp,"end")==0) break;
        DLX dl(SI*SI*SI,(SI+SI+SI)*SI+SI*SI);
        REP(i,SI) REP(j,SI)
        {
            int ct = i*SI+j;
            int row = ct*SI;
            int block = (i/3)*3+(j/3);
            int col[4] = {ct,SI*SI+(i*SI),SI*SI*2+(j*SI),SI*SI*3+(block*SI)};
            if(mp[ct]!='.')
            {
                int off = mp[ct]-'1';
                dl.SetBit(row+off,col[0]);
                FOR(kk,1,4) dl.SetBit(row+off,col[kk]+off);
            }
            else
            {
                REP(k,SI)
                {
                    dl.SetBit(row+k,col[0]);
                    FOR(kk,1,4) dl.SetBit(row+k,col[kk]+k);
                }
            }
        }
        dl.PrintAns();
    }
    return 0;
}
//.................................................................................
